<template>
  <el-card class="content-card">
    <template #header>
      <div class="card-header">
        <h3>待办事项</h3>
        <el-badge :value="totalPendingCount" :hidden="totalPendingCount === 0" />
      </div>
    </template>
    <div class="pending-list">
      <div
        class="pending-item"
        v-for="(item, index) in pendingStats"
        :key="index"
        @click="goToPage(item.url)"
      >
        <div class="pending-title">{{ item.name }}</div>
        <div class="pending-count">{{ item.count }}</div>
      </div>
      <div v-if="pendingStats.length === 0" class="no-data">暂无待办事项</div>
    </div>
  </el-card>
</template>

<script setup lang="ts">
  import { useRouter } from 'vue-router'
  import { ElMessage } from 'element-plus'

  interface PendingItem {
    name: string
    count: number
    url: string
  }

  interface Props {
    pendingStats: PendingItem[]
    totalPendingCount: number
  }

  const props = defineProps<Props>()
  const router = useRouter()

  // 跳转到指定页面
  const goToPage = (url: string) => {
    if (url) {
      router.push(url).catch(err => {
        ElMessage.error('页面跳转失败')
        console.error('页面跳转失败:', err)
      })
    }
  }
</script>

<style scoped>
  /* 待办事项样式 */
  .content-card {
    height: 100%;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    border: none;
  }

  .card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 500;
  }

  .pending-list {
    min-height: 200px;
  }

  .pending-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 0;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    transition: all 0.3s ease;
  }

  .pending-item:hover {
    background-color: #f8f9fa;
    padding-left: 8px;
  }

  .pending-item:last-child {
    border-bottom: none;
  }

  .pending-title {
    font-size: 14px;
    color: #333;
  }

  .pending-count {
    font-size: 16px;
    font-weight: bold;
    color: #e6a23c;
    background: #fef9e7;
    padding: 4px 8px;
    border-radius: 12px;
    min-width: 24px;
    text-align: center;
  }

  .no-data {
    text-align: center;
    padding: 40px 20px;
    color: #999;
    font-size: 14px;
  }

  /* 响应式设计 */
  @media (max-width: 768px) {
    .pending-list {
      min-height: 180px;
    }

    .pending-item {
      padding: 12px 0;
    }

    .pending-title {
      font-size: 13px;
    }

    .pending-count {
      font-size: 14px;
      padding: 2px 6px;
    }
  }
</style>
